<?php

namespace common\repositories\myhtsq;

use common\repositories\BaseRepository;
use common\entities\myhtsq\InvoiceBusinessUnitEntity;

/**
 * Description of InvoiceBusinessUnitRepository
 * 开票单位仓储
 * @author chenxc
 */
class InvoiceBusinessUnitRepository extends BaseRepository {

    /**
     * 构造方法
     * @param unknown $config (optional)
     */
    public function __construct($config = []) {
        parent::__construct($config);
    }

    /**
     * 获取开票单位
     * @param string $keyword 搜索关键字
     * @return array 
     */
    public static function getInvoiceBusinessUnit($keyword = '') {
        $query = InvoiceBusinessUnitEntity::find()
                ->select("BUGUID,BUName,BUFullName,BUCode");
        if (!empty($keyword)) {
            $query->where(['like', 'BUName', $keyword]);
        }

        return $query->all();
    }

    /**
     * 根据开票单位名称获取开票单位信息
     * @param string $BUName
     *
     * @return array|null|\yii\db\ActiveRecord
     */
    public static function getInvoiceBusinessUnitByBUName($BUName = '')
    {
        return InvoiceBusinessUnitEntity::find()->where(['BUName' => $BUName])->asArray()->one();
    }

}
